package com.campus.mapper;

import com.campus.annotation.AutoFill;
import com.campus.enumeration.OperationType;
import com.campus.pojo.dto.PostPageQueryDTO;
import com.campus.pojo.entity.Post;
import com.campus.pojo.vo.PostVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface PostMapper {
    Page<PostVO> pageQuery(PostPageQueryDTO postPageQueryDTO);

    PostVO getById(Long id);


    @AutoFill(value = OperationType.UPDATE)
    void update(Post post);

    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into lost_found_post " +
            "(title, content, post_type, item_name, lost_time, found_time, location, contact_info, image, status, reject_reason, cancel_reason, user_id, create_time, update_time) " +
            "values (#{title}, #{content}, #{postType}, #{itemName}, #{lostTime}, #{foundTime}, #{location}, #{contactInfo}, #{image}, #{status}, #{rejectReason}, #{cancelReason}, #{userId}, #{createTime}, #{updateTime})")
    void insert(Post post);

    @Select("select user_id from lost_found_post where id = #{id}")
    Long getUserId(Long id);

    @Select("select count(*) from lost_found_post where status = #{status}")
    Integer countStatus(Integer status);
}
